package api

import (
	"beta/pkg/app"
	"beta/pkg/e"
	"beta/pkg/logger"
	"beta/pkg/util"
	"beta/service/lts_service"
	"github.com/gin-gonic/gin"
	"net/http"
)

func AddLtsJob(c *gin.Context) {
	appG := app.Gin{C: c}
	traceId := util.GetTraceID(c)
	jobName := c.Query("job_name")
	namespace := c.Query("namespace")

	if jobName == "" || namespace == "" {
		logger.ZapLogger.Infow("【执行lts任务】", "请求参数", "不能为空")
		appG.Response(http.StatusBadRequest, e.InvalidParams, traceId, nil)
		return
	}

	ltsService := lts_service.LtsService{TraceId: traceId, Namespace: namespace}
	err := ltsService.AddLtsJob(jobName)
	if err != nil {
		appG.Response(http.StatusInternalServerError, e.LtsJobCreateErr, traceId, nil)
		return
	}

	appG.Response(http.StatusOK, e.SUCCESS, traceId, nil)

}